<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!-- 主体内容 -->
<div class="layui-fluid" >



    <form class="layui-form" id="form1">
        <div class="layui-card">
            <div class="layui-card-header"  style="color:#d02e25;font-family: '楷体'; ">
                添加组织
            </div>
            <div class="layui-card-body">
                <div class="layui-form-item">
                    <label class="layui-form-label">组织号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="id" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>

                    <label class="layui-form-label">组织名</label>
                    <div class="layui-input-inline">
                        <div class="layui-inline" style="width: 100%;">

                            <div class="layui-input-inline" style="width: 100%;">
                                <select name="branchName" id="branchName" lay-verify="required" lay-search="" style="width: 100%;">

                                </select>
                            </div>
                        </div>
                    </div>

                    <label class="layui-form-label">上级党组织</label>
                    <div class="layui-input-inline">
                        <div class="layui-inline" style="width: 100%;">

                            <div class="layui-input-inline" style="width: 100%;">
                                <select name="superiorBranch" id="superiorBranch" lay-verify="required" lay-search="" style="width: 100%;">

                                </select>
                            </div>
                        </div>
                    </div>
                </div>



                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">地址</label>
                    <div class="layui-input-inline" style="width: 500px;">
                        <input type="text" name="address"  lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>


                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">党组织类别</label>
                    <div class="layui-input-block">
                        <input type="text" name="branchCategory"  lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">党组织书记</label>
                    <div class="layui-input-inline" style="width: 30%;">
                        <input type="text" name="partyOrganizationSecretary"  lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>

                    <label class="layui-form-label">党组织书记电话号码&nbsp;</label>
                    <div class="layui-input-inline" style="width: 30%;">
                        <input type="text" name="secretaryTelephone"  lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>



                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">成立时间</label>
                    <div class="layui-input-inline">
                        <input type="text" name="establishmentDate" id="establishmentDate" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">&nbsp;</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="isHaveFirstsecretary" title="是否有第一书记">
                        <input type="checkbox" name="isHaveParttime" title="是否有兼职委员">
                        <input type="checkbox" name="isHaveEducationplace" title="是否有教育站点">
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">党组织联系人</label>
                    <div class="layui-input-inline">
                        <input type="text" name="partyOrganizationContact"  lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>

                    <label class="layui-form-label">党组织联系电话</label>
                    <div class="layui-input-inline">
                        <input type="text" name="contactTelephone"  lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>

                    <label class="layui-form-label">党组织人数</label>
                    <div class="layui-input-inline">
                        <input type="text" name="number"  lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>




                <div class="layui-form-item" style="text-align: center">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="ok">提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary" id="reset">重置</button>
                    </div>
                </div>


            </div>
        </div>
    </form>


</div>



<script type="application/javascript">
    // layui.use(['form','laydate'], function(){

        var form = layui.form;
        var laydate = layui.laydate;



        //执行一个laydate实例
        laydate.render({
            elem: '#establishmentDate' //指定元素
        });
        form.render();

        form.on('submit(ok)',function (data) {
            if(data.field.isHaveFirstsecretary=="on"){
                data.field.isHaveFirstsecretary = "是";
            }else{
                data.field.isHaveFirstsecretary = "否";
            }

            if(data.field.isHaveParttime=="on"){
                data.field.isHaveParttime = "是";
            }else{
                data.field.isHaveParttime = "否";
            }

            if(data.field.isHaveEducationplace=="on"){
                data.field.isHaveEducationplace = "是";
            }else{
                data.field.isHaveEducationplace = "否";
            }


            $.ajax({
                type:"post",
                url:"/ajax/party/admin/addgroup",
                contentType : 'application/json;charset=utf-8',
                //设置请求头信息
                dataType:"json",
                data:JSON.stringify(data.field),
                success:function (res) {
                    if(res.code==0){
                        layer.alert("OK");
                    }
                }
            })

            return false;
        })
    // });

</script>

<script>
    $.post("/ajax/party/admin/branches",{
        check:1024
    },function (res) {
        if(res.code==0){
            //得到所有级别
            var names = new Array();
            for(var i=0;i<res.data.length;i++){
                names[i]=res.data[i].branchName;
            }
            //将等级动态显示到界面上
            for(var i=0;i<names.length;i++){
                document.getElementById("branchName").options.add(new Option(names[i],names[i]));
                document.getElementById("superiorBranch").options.add(new Option(names[i],names[i]));
                $("#isHaveFirstsecretary").attr("checked",true);
            }

        }
        else{
            layer.alert("未知错误！");
        }
        form.render();
    })
</script>